package nio;

import java.nio.ByteBuffer;

/**
 * @author RJA
 * @version V1.0
 * @Title: nio.demo_1
 * @Description:
 * @date 2019/9/5 16:31
 */
public class NioTest06 {
    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(10);
        for(int i = 0;i < buffer.capacity();++i){
            buffer.put((byte)i);
        }
        buffer.position(2);
        buffer.limit(6);
        ByteBuffer sliceBuffer = buffer.slice();
        for(int i = 0;i < sliceBuffer.capacity();++i){
            byte b = sliceBuffer.get(i);
            b *= 2;
            sliceBuffer.put(b);
        }
        buffer.position(0);
        buffer.limit(buffer.capacity());

        while (buffer.hasRemaining()){
            System.out.println(buffer.get());
        }
    }
}
